package com.sc.myspringbootmo.controller;

import com.sc.myspringbootmo.pojo.Content;
import com.sc.myspringbootmo.pojo.Tags;
import com.sc.myspringbootmo.service.IContentService;
import com.sc.myspringbootmo.service.ITagsService;
import com.sc.myspringbootmo.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 内容（视频/图文/文本）表 前端控制器
 * </p>
 *
 * @author svblack
 * @since 2025-09-23 03:36:11
 */
@RestController
@RequestMapping("/content")
public class ContentController {
    @Autowired
    IContentService contentService;
    @Autowired
    ITagsService tagsService;

    @RequestMapping("/tags")
    public List<Tags> getAll() {
        return tagsService.getAllTags();
    }



    @RequestMapping("/add")//用来增加普通作品
    ResponseMsg add(@RequestBody Content content) {
        if (contentService.save(content)) {
            Integer contentId = content.getContentId();
            return ResponseMsg.getInstance(200,null, Map.of("contentId", contentId));

        }
        return ResponseMsg.getInstance(500,"后端添加失败");
    }
//修改查询数据
    @RequestMapping("/getById")
    ResponseMsg getById(Integer contentId) {
        if (contentId == null) {
            return ResponseMsg.getInstance(-200, "修改查询失败", null);
        }
        Content content = contentService.getById(contentId);
        if (content == null) {
            return ResponseMsg.getInstance(-200, "修改数据已经不存在", null);

        }
        return ResponseMsg.getInstance(200, "修改查询数据成功", content);
    }

    //修改数据
    @RequestMapping("/update")
    ResponseMsg update(@RequestBody Content content) {
        if (content.getContentId() == null) {
            return ResponseMsg.getInstance(-200, "修改的数据ID为空", null);
        }
        contentService.updateById(content);
        return ResponseMsg.success();
    }


}
